package com.codes.controller;

import com.codes.core.common.CConstant;
import com.codes.core.common.result.Result;
import com.codes.core.utils.UserUtil;
import com.codes.service.OpinionSV;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Date 2020/6/13 15:35
 * @Created by peanut
 */

@Api(tags = "意见反馈接口")
@RestController
@RequestMapping("/opinion")
public class OpinionCtr {

    @Autowired
    private OpinionSV opinionSV;

    @ApiOperation("添加意见")
    @PostMapping("/add")
    public Result addOpinion(@RequestBody Map<String,Object> map, HttpServletRequest request){

        Integer opinionId  = MapUtils.getInteger(map,"opinionId");

        if(null != opinionId){
            opinionSV.updateByPrimaryKeySelective(map);
            return Result.success("意见修改成功");
        }
        opinionSV.insertSelective(map);
        return Result.success("意见添加成功");
    }

    @ApiOperation("意见反馈列表")
    @GetMapping("/list")
    public Result getList(@RequestParam( defaultValue="1",required=true) int   page,
                          @RequestParam( defaultValue="10",required=true) Integer limit,
                          @RequestParam Map<String,Object> map ) {
        PageHelper.startPage(page,limit);
        List<Map<String, Object>> list =opinionSV.getListByMap(map);
        PageInfo<Map<String, Object>> info = new PageInfo< >(list);
        return Result.pages(info.getList(),(int)info.getTotal());
    }

    @ApiOperation("查看意见详情")
    @GetMapping("/get-info")
    public Result getInfo(@RequestParam Map<String,Object> map){


        return Result.failed("获取详情失败");

    }


}